package com.celan.year2023.month05.day01;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author Celan
 * @ClassName Solution02
 * @description: TODO
 * @date 2023/05/01
 * @version: 1.0
 */
public class Solution02 {
    public List<String> findRepeatedDnaSequences(String s) {
        List<String> res = new ArrayList<>();
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i <= s.length() - 10; i++) {
            String sub = s.substring(i, i + 10);
            if (map.containsKey(sub)) {
                map.put(sub, map.get(sub) + 1);
            } else {
                map.put(sub, 1);
            }
        }
        for (String str : map.keySet()) {
            if (map.get(str) > 1) res.add(str);
        }
        return res;
    }
}
